import WorkerMSDB
import MSData
import sys
reader = WorkerMSDB.Worker('localhost', '2929', 'PGSMData', 'sa', 'safeinside')
reader.connect()
c = reader.connection.cursor()
query = 'SELECT deviceId,eventTime,rs232str FROM _rs232_data WHERE deviceId=50'
c.execute(query)
d = c.fetchall()

for s in d:
    e = MSData.MSEvent()
    try:
        e.fromBolid(reader.parseEventBolid(s))
        print s[2].decode('cp866'), e.contactIdType, e.contactIdGroup, e.contactIdZona
    except Exception, err:
        print s[2].decode('cp866'), str(err)


